package cn.zfs.datasource.util;

public class BaseResponse<T> {

    private static final Integer RESULT_SUCCESS = 200;
    private static final Integer RESULT_FAIL = 400;
    private static final String REPLACESTR = "{}";
    private static final String REGEX = "\\{\\}";

    private Integer result;
    private String msg;
    private T data;


    public static BaseResponse staticSuccess(String msg, Object... obj) {
        msg = StringUtil.formatString(msg, REPLACESTR, REGEX, obj);
        return new BaseResponse(RESULT_SUCCESS, msg);
    }

    public static BaseResponse fail(String msg, Object... obj) {
        msg = StringUtil.formatString(msg, REPLACESTR, REGEX, obj);
        return new BaseResponse(RESULT_FAIL, msg);
    }

    public BaseResponse<T> success(String msg, T data) {
        this.msg = msg;
        this.result = RESULT_SUCCESS;
        this.data = data;
        return this;
    }

    public BaseResponse<T> success(T data) {
        this.result = RESULT_SUCCESS;
        this.data = data;
        return this;
    }

    public BaseResponse() {
    }

    private BaseResponse(Integer result, String msg) {
        this.result = result;
        this.msg = msg;
    }

    public Integer getResult() {
        return result;
    }

    public void setResult(Integer result) {
        this.result = result;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
